package com.newtouch.bxzs.common.base.util;

import cn.hutool.core.bean.BeanUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 实体转bean工具类
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020年12月28日</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 * 
 * @author Amour
 * 
 * @version 1.0.0
 * @since 1.0.0
 */
public class EntityToBeanUtils {

	public static <T, E> List<T> copyBean(List<E> list, Class<T> target) {

		List<T> targetList = new ArrayList<>(list.size());

		for (E e : list) {
			T t = null;
			try {
				t = target.newInstance();
			} catch (InstantiationException ex) {
				ex.printStackTrace();
			} catch (IllegalAccessException ex) {
				ex.printStackTrace();
			}
			BeanUtil.copyProperties(e, t);
			targetList.add(t);
		}

		return targetList;
	}

}
